import java.util.Scanner;

public class Main {


        //装箱问题
        public static void main(String[] args) {
                Scanner in = new Scanner(System.in);
                int v = in.nextInt();
                int n = in.nextInt();
                int[] arr = new int[n+1];
                for (int i = 1; i <=  n; i++) {
                        arr[i] = in.nextInt();
                }
                int[][] dp = new int[n+1][v+1];
                for (int i = 1; i <= n; i++) {
                        for (int j = 0; j <= v; j++) {
                                dp[i][j] = dp[i-1][j];
                                if(j>=arr[i]){
                                        dp[i][j] = Math.max(dp[i][j],dp[i-1][j-arr[i]]+arr[i]);
                                }
                        }
                }
                System.out.println(v-dp[n][v]);
        }













        //数组变换
        public static void main2(String[] args) {
                Scanner in=  new Scanner(System.in);
                int n = in.nextInt();
                int[] arr = new int [n];
                int b= 0;
                for (int i = 0; i < n; i++) {
                        arr[i] = in.nextInt();
                        b = Math.max(b,arr[i]);
                }
                boolean flag = true;
                for (int i = 0; i < n; i++) {
                        if(b%arr[i]!=0){
                                flag = false;
                                break;
                        }
                        int  x = b/arr[i];
                        if((x-(x&-x))!= 0){
                                flag = false;
                                break;
                        }
                }
                if(flag) System.out.println("YES");
                else System.out.println("NO");
        }


















        //添加字符
        public static void main1(String[] args) {
                Scanner in = new Scanner(System.in);
                char[] a = in.next().toCharArray();
                char[] b = in.next().toCharArray();
                int m = a.length;
                int n = b.length;
                int ret  = m;

                for (int i = 0; i <= n-m; i++) {
                        int tmp = 0;
                        for (int j = 0; j < m; j++) {
                                if(a[j] != b[i+j]){
                                        tmp++;
                                }
                        }
                        ret = Math.min(ret,tmp);
                }
                System.out.println(ret);
        }



















}
